package com.shopowner.controller;

import com.shopowner.dto.DTO;
import com.shopowner.entity.Store;
import com.shopowner.page.PageInfo;
import com.shopowner.service.StoreService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@CrossOrigin
@Controller
@RequestMapping("/storeController")
public class StoreController {
	@Resource
	StoreService storeService;
	@RequestMapping("/getAllStore")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Store> getAllStore() throws Exception {
    	System.out.println("查询全部店长");
		return storeService.getAllStores();
    }

	@RequestMapping("/deleteStoreByStno/{stno}")
	@ResponseBody
    public DTO<Store> deleteStoreByStno(@PathVariable("stno") String stno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(stno+"删除店长");
    	return storeService.deleteStoreByStno(stno);
    }

	@RequestMapping("/updateStoreByStno")
	@ResponseBody
	public DTO<Store> updateStoreByStno(@RequestBody Store store) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改店长");
		return storeService.updateStoreByStno(store);
	}


	@RequestMapping("/addStore")
	@ResponseBody
	public DTO<Store> addStore(@RequestBody Store store) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加店长");
		System.out.println(store);
 		return storeService.addStore(store);
	}

	@RequestMapping("/getStoreByPage")
	@ResponseBody
	public DTO<Store> getStoreByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页店长");
		return storeService.getStoreByPage(pageInfo);
	}
	@RequestMapping("/selectStoreWithCoach/{stno}")
	@ResponseBody
	public DTO<Store> selectStoreWithCoach(@PathVariable("stno") String stno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询门店附上教练");
		return storeService.selectStoreWithCoach(stno);
	}
	@RequestMapping("/selectStoreWithshopowner/{stno}")
	@ResponseBody
	public DTO<Store> selectStoreWithshopowner(@PathVariable("stno") String stno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询店长附上门店");
		return storeService.selectStoreWithshopowner(stno);
	}
}